package com.metis.document.parse.dialog.pipeline.impl;

import com.metis.document.parse.dialog.pipeline.TextPostProcess;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
@Component
public class UnknownTextProcess implements TextPostProcess {

    private static final String REGEX = "(如错.*?未找到所示)|(如错.*?未找到)|(错误.*?所示)|(如.*?not found 所示)|(如.*?not found7所示)|(not found 所示)";

    private static final Pattern PATTERN = Pattern.compile(REGEX);


    @Override
    public String process(@NotNull String input) {
        if(StringUtils.isEmpty(input)){
            return input;
        }

        Matcher matcher = PATTERN.matcher(input);
        StringBuffer result = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(result, "");
        }
        matcher.appendTail(result);

        return result.toString().replace("，。","。");
    }

}
